function ohelp = root_Help(hfile, m)
% ROOT::Help  - get Help on methods
%
% FORMAT:       help = BVQXfile.Help([typmeth]);
%
% Input fields:
%
%       typmeth     optional type of method
%
% Output fields:
%
%       help        complete help over all methods

% Version:  v0.8a
% Build:    9102322
% Date:     Oct-23 2009, 10:12 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'root') || ...
    hfile.L ~= 1
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to ''%s''.', ...
        mfilename ...
    );
end

% get list of extensions
x = BVQXfile(0, 'extensions');
xf = fieldnames(x);

if nargin > 1 && ...
    ischar(m) && ...
   ~isempty(m)
    m = lower(m(:)');
    
    % rethrow error if necessary
    try
        obj = cell(1, 1);
        % test for extension
        if isfield(x, m)
            
            % pass good object
            obj{1} = new(hfile, m);
            ohelp = aft_Help(obj{1});
            clearbvqxobjects(obj);
            
        % or pass to aft_Help for root
        else
            ohelp = aft_Help(hfile, m);
        end
    catch
        clearbvqxobjects(obj);
        rethrow(lasterror);
    end
    return;
end

% remove double entries
for xc = numel(xf):-1:2
    if x.(xf{xc}){2} == x.(xf{xc-1}){2}
        xf(xc) = [];
    end
end
xf = sort(xf);

% create new objects and get help
obj = [];
ohelp = cell(numel(xf), 1);
for xc = numel(xf):-1:1
    try
        if strcmpi(xf{xc}, 'root')
            ohelp{xc} = aft_Help(hfile);
        else
            obj = new(hfile, xf{xc});
            ohelp{xc} = aft_Help(obj);
        end
    catch
        ohelp{xc} = '';
    end
    if ~isempty(obj)
        bvqxfile_clear(obj.L);
    end
    obj = [];
    ohelp{xc} = regexprep(ohelp{xc}, '^No methods.*$', '');
    if isempty(ohelp{xc})
        ohelp(xc) = [];
    end
end
ohelp = gluetostringc(ohelp, char(10));
